/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelEntityBubble
    {
        private readonly Dictionary<int, CfgLevelEntityBubble> _dataMap;
        private readonly List<CfgLevelEntityBubble> _dataList;


        public TbCfgLevelEntityBubble(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelEntityBubble _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelEntityBubble(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelEntityBubble>(size * 3 / 2);
            _dataList = new List<CfgLevelEntityBubble>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelEntityBubble _v;
                _v = CfgLevelEntityBubble.DeserializeCfgLevelEntityBubble(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelEntityBubble> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelEntityBubble> DataList => _dataList;

        public CfgLevelEntityBubble Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelEntityBubble] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelEntityBubble GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "levelentitybubble";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelEntityBubble LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelEntityBubble(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelEntityBubble
    {
        private CfgLevelEntityBubble(ByteBuf _buf, _TbCommonLevelEntityBubble _commonData)
        {
            Id = _buf.ReadInt();
            DisplayCondition = _buf.ReadInt();
            Desc = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; ImageContent = _commonData._field0[dataIndex]; }
            JumpId = _buf.ReadInt();
            DisplaySpeed = _buf.ReadFloat();
            BubbleLifeTime = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; PositionOffset = _commonData._field1[dataIndex]; }

            PostInit();
        }

        internal static CfgLevelEntityBubble DeserializeCfgLevelEntityBubble(ByteBuf _buf, _TbCommonLevelEntityBubble _commonData)
        {
            return new CfgLevelEntityBubble(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 显示条件
        /// </summary>
        public int DisplayCondition { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Desc { get; private set; }
        /// <summary>
        /// 图片内容
        /// </summary>
        public string ImageContent { get; private set; }
        /// <summary>
        /// 跳转id
        /// </summary>
        public int JumpId { get; private set; }
        /// <summary>
        /// 每秒出字速度(0全出)
        /// </summary>
        public float DisplaySpeed { get; private set; }
        /// <summary>
        /// 气泡框生存时间 (毫秒)
        /// </summary>
        public int BubbleLifeTime { get; private set; }
        /// <summary>
        /// 头顶屏幕偏移（x，y）
        /// </summary>
        public IReadOnlyList<float> PositionOffset { get; private set; }

        /// <summary>
        /// ImageContent 资源全路径
        /// </summary>
        public string ImageContent_fullPath => $"Res/05_Images/Sprite/BubbleImage/{ImageContent}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelEntityBubble
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<float>> _field1 { get; private set; }
        internal _TbCommonLevelEntityBubble(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new float[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ float[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new float[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ float __v1; __v1 = _buf.ReadFloat(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
